package com.kmu.kmucampus.adapter.treeViewAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.kmu.kmucampus.R;

import java.util.List;

import mytest.ssw.www.mylibrary.DeptNode;

//import db.etc.cn.myapplication.tree.bean.Node;

public class SimpleTreeAdapter<T> extends TreeListViewAdapter<T>
{

	public SimpleTreeAdapter(ListView mTree, Context context, List<DeptNode> datas,
							 int defaultExpandLevel) throws IllegalArgumentException,
			IllegalAccessException
	{
		super(mTree, context,datas, defaultExpandLevel);
	}

	//@Override
	public View getConvertView(final DeptNode node , int position, View convertView, ViewGroup parent)
	{
		ViewHolder viewHolder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.list_item, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.icon = (ImageView) convertView
					.findViewById(R.id.id_treenode_icon);
			viewHolder.label = (TextView) convertView
					.findViewById(R.id.id_treenode_label);
			viewHolder.icon_select= (ImageView) convertView
					.findViewById(R.id.id_selectFlag_icon);
			convertView.setTag(viewHolder);
		} else
		{
			viewHolder = (ViewHolder) convertView.getTag();

		}
		viewHolder.icon_select.setVisibility(View.VISIBLE);
		viewHolder.icon_select.setImageResource(node.getSelectIcon());

		if (node.getIcon() == -1)
		{
			viewHolder.icon.setVisibility(View.INVISIBLE);
		} else
		{
			viewHolder.icon.setVisibility(View.VISIBLE);
			viewHolder.icon.setImageResource(node.getIcon());
			//viewHolder.checkBox.setChecked(false);

//			final ViewHolder finalViewHolder = viewHolder;
//			viewHolder.checkBox.setOnClickListener(new View.OnClickListener() {
//				@Override
//				public void onClick(View v) {
//					finalViewHolder.checkBox.setText(node.getpNum());
//					Log.i("ttt", node.getNum().toString());
//				}
//			});
		}
		viewHolder.label.setText(node.getName());
		//viewHolder.checkBox.setText(node.getNum());

		return convertView;
	}

	private final class ViewHolder
	{
		ImageView icon;
		TextView label;
		ImageView icon_select;
	}

}
